const mongoose = require('mongoose');

// 定义用户数据的 Schema（结构 + 校验）
const categorySchema = new mongoose.Schema({
  name: { 
    type: String, 
    required:true,
  },
  alias: { 
    type: String, 
    required:true,
  },
  userId: { 
    type: mongoose.Schema.Types.ObjectId, 
    ref: 'User',
    required: true
  }
});

categorySchema.index({ userId: 1, name: 1 }, { unique: true });
categorySchema.index({ userId: 1, alias: 1 }, { unique: true });

// 创建并导出 Model（对应 MongoDB 的 "categories" 集合）
const Category = mongoose.model('Category', categorySchema);

module.exports = Category;